


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
  <title>Coverage Report :: ArrayConverter</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
  </style>
</head>

<body>
<div class="header"></div>

<div class="content">
<div class="breadCrumbs">
    [ <a href="../../index.html">all classes</a> ]
    [ <a href="../index.html">at.schauer.gregor.vienna.convert.vienna.util</a> ]
</div>

<h1>Coverage Summary for Class: ArrayConverter (at.schauer.gregor.vienna.convert.vienna.util)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">ArrayConverter</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/ 1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    75%
  </span>
  <span class="absValue">
    (6/ 8)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    79.2%
  </span>
  <span class="absValue">
    (19/ 24)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<div class="sourceCode"><i>1</i>&nbsp;/*
<i>2</i>&nbsp; * Copyright 2012 Gregor Schauer
<i>3</i>&nbsp; *
<i>4</i>&nbsp; * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<i>5</i>&nbsp; * you may not use this file except in compliance with the License.
<i>6</i>&nbsp; * You may obtain a copy of the License at
<i>7</i>&nbsp; *
<i>8</i>&nbsp; *      http://www.apache.org/licenses/LICENSE-2.0
<i>9</i>&nbsp; *
<i>10</i>&nbsp; * Unless required by applicable law or agreed to in writing, software
<i>11</i>&nbsp; * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<i>12</i>&nbsp; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<i>13</i>&nbsp; * See the License for the specific language governing permissions and
<i>14</i>&nbsp; * limitations under the License.
<i>15</i>&nbsp; */
<i>16</i>&nbsp;package at.schauer.gregor.vienna.convert.vienna.util;
<i>17</i>&nbsp;
<i>18</i>&nbsp;import at.schauer.gregor.vienna.context.ViennaContext;
<i>19</i>&nbsp;import at.schauer.gregor.vienna.context.ViennaContextAware;
<i>20</i>&nbsp;import at.schauer.gregor.vienna.convert.factory.ConverterFactory;
<i>21</i>&nbsp;import at.schauer.gregor.vienna.convert.factory.ConverterFactoryAware;
<i>22</i>&nbsp;import at.schauer.gregor.vienna.convert.vienna.ViennaToStringStyle;
<i>23</i>&nbsp;import at.schauer.gregor.vienna.convert.vienna.base.SeparatorConverter;
<i>24</i>&nbsp;import at.schauer.gregor.vienna.serializer.Serializer;
<i>25</i>&nbsp;import at.schauer.gregor.vienna.util.ViennaUtils;
<i>26</i>&nbsp;import org.apache.commons.lang3.ClassUtils;
<i>27</i>&nbsp;import org.apache.commons.lang3.builder.ToStringBuilder;
<i>28</i>&nbsp;import org.springframework.util.StringUtils;
<i>29</i>&nbsp;
<i>30</i>&nbsp;import javax.annotation.Nonnull;
<i>31</i>&nbsp;import java.lang.reflect.Array;
<i>32</i>&nbsp;
<i>33</i>&nbsp;/**
<i>34</i>&nbsp; * @author Gregor Schauer
<i>35</i>&nbsp; */
<b class="nc"><i>36</i>&nbsp;@Deprecated</b>
<b class="fc"><i>37</i>&nbsp;public class ArrayConverter implements SeparatorConverter&lt;Object[]&gt;, ConverterFactoryAware, ViennaContextAware {</b>
<b class="fc"><i>38</i>&nbsp;	protected ViennaToStringStyle style = new ViennaToStringStyle();</b>
<i>39</i>&nbsp;	protected ViennaContext ctx;
<i>40</i>&nbsp;
<i>41</i>&nbsp;	@Override
<i>42</i>&nbsp;	public Object[] sourceToTarget(String source, Class&lt;? extends Object[]&gt; targetClass) {
<b class="fc"><i>43</i>&nbsp;		source = source.substring(source.indexOf(Serializer.CLASS_OBJECT_SEPARATOR) + 3, source.length() - 2);</b>
<b class="fc"><i>44</i>&nbsp;		String[] fields = StringUtils.delimitedListToStringArray(source, getSeparator());</b>
<b class="fc"><i>45</i>&nbsp;		Object[] target = (Object[]) Array.newInstance(targetClass.getComponentType(), fields.length);</b>
<b class="fc"><i>46</i>&nbsp;		for (int i = 0; i &lt; fields.length; i++) {</b>
<i>47</i>&nbsp;			try {
<b class="fc"><i>48</i>&nbsp;				String sourceElement = fields[i];</b>
<b class="fc"><i>49</i>&nbsp;				Class clazz = ClassUtils.getClass(ViennaUtils.ConverterUtils.typeFromString(sourceElement));</b>
<b class="fc"><i>50</i>&nbsp;				String value = ViennaUtils.ConverterUtils.valueFromString(sourceElement);</b>
<b class="fc"><i>51</i>&nbsp;				Array.set(target, i, ViennaUtils.DeserializationUtils.load(ctx, clazz, value));</b>
<b class="nc"><i>52</i>&nbsp;			} catch (ClassNotFoundException e) {</b>
<b class="nc"><i>53</i>&nbsp;				throw new RuntimeException(e);</b>
<b class="fc"><i>54</i>&nbsp;			}</b>
<i>55</i>&nbsp;		}
<b class="fc"><i>56</i>&nbsp;		return target;</b>
<i>57</i>&nbsp;	}
<i>58</i>&nbsp;
<i>59</i>&nbsp;	@Override
<i>60</i>&nbsp;	public String targetToSource(Object... target) {
<b class="fc"><i>61</i>&nbsp;		ToStringBuilder builder = new ToStringBuilder(target, style);</b>
<b class="fc"><i>62</i>&nbsp;		builder.append(target);</b>
<b class="fc"><i>63</i>&nbsp;		return builder.toString();</b>
<i>64</i>&nbsp;	}
<i>65</i>&nbsp;
<i>66</i>&nbsp;	@Override
<i>67</i>&nbsp;	public String getSeparator() {
<b class="fc"><i>68</i>&nbsp;		return style.getArraySeparator();</b>
<i>69</i>&nbsp;	}
<i>70</i>&nbsp;
<i>71</i>&nbsp;	public void setSeparator(String separator) {
<b class="nc"><i>72</i>&nbsp;		style.setArraySeparator(separator);</b>
<b class="nc"><i>73</i>&nbsp;	}</b>
<i>74</i>&nbsp;
<i>75</i>&nbsp;	@Override
<i>76</i>&nbsp;	public void setViennaContext(ViennaContext viennaContext) {
<b class="fc"><i>77</i>&nbsp;		this.ctx = viennaContext;</b>
<b class="fc"><i>78</i>&nbsp;	}</b>
<i>79</i>&nbsp;
<i>80</i>&nbsp;	@Override
<i>81</i>&nbsp;	public void setConverterFactory(@Nonnull ConverterFactory converterFactory) {
<i>82</i>&nbsp;//		converterFactory.register(Object[].class, this);
<b class="fc"><i>83</i>&nbsp;	}</b>
<i>84</i>&nbsp;}
</div>
</div>

<div class="footer">
    
    <div style="float:right;">generated on 2012-07-17 20:22</div>
</div>
</body>
</html>
